package ctn.dao.hibernate.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import ctn.contant.PlugContant;
import ctn.dao.inteface.LinkEventDao;
import ctn.hibernate.po.CtnLinkApprove;
import ctn.hibernate.po.CtnLinkEvent;
@Component
public class LinkEventDaoImpl extends AbstractCTNDAO implements LinkEventDao {

	@Override
	public CtnLinkEvent insertCtnLinkEvent(CtnLinkEvent cle) {
		getHibernateTemplate().persist(cle);
		return cle;
	}

	@Override
	public void insertCtnLinkApprove(CtnLinkApprove cla) {
		getHibernateTemplate().save(cla);
	}

	@Override
	public CtnLinkApprove getCtnLinkApproveByID(String uUID) {
		
		return getHibernateTemplate().get(CtnLinkApprove.class, uUID);
	}

	@Override
	public void updateLinkApprove(CtnLinkApprove cla) {
		getHibernateTemplate().update(cla);
		
	}

	@Override
	public int getNoAcceptLinkCount(CtnLinkApprove cla) {
		List<CtnLinkApprove> list=getHibernateTemplate().find("From CtnLinkApprove t where t.ctnLinkEvent.id=?", cla.getCtnLinkEvent().getId());
		int count=0;
		for(CtnLinkApprove po:list){
			if(PlugContant.Link_APPROVE_STATUS_APPROVE.equals(po.getStatus())){
				count++;
			}
		}
		
		return count;
	}

	@Override
	public CtnLinkEvent getCtnLinkEventByID(Long eventID) {
		
		return getHibernateTemplate().get(CtnLinkEvent.class, eventID);
	}
	
}
